package com.yazi.mxz.person.controller.firm;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;




import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.myframework.smhj.common.tool.PageLink;
import com.myframework.smhj.hibernate.Page;
import com.myframework.smhj.hibernate.Searching;
import com.myframework.smhj.hibernate.Sort;
import com.yazi.mxz.common.entity.beans.MemberVip;
import com.yazi.mxz.common.service.MemberVipService;
import com.yazi.mxz.person.controller.MyPageLink;

@Controller("firm-memberVipController")
@RequestMapping("/firm/memberVip")
public class MemberVipController extends BaseController {
	private static Logger log = LoggerFactory.getLogger(MemberVipController.class);

	@Resource
	MemberVipService memberVipService;

	@RequestMapping("/list")
	public String list(MemberVip vip, Searching si, Model model) {
		debug(log, "查询企业会员");
		Page<MemberVip> page;
		PageLink pl;
		try {
			// 只能查当前企业的充值会员
			vip.setCompany(getCompany());
			// 默认按加入时间倒序排序
			if (null == si.getSorts()) {
				List<Sort> sorts = new ArrayList<Sort>();
				sorts.add(new Sort("addTime", true));
				si.setSorts(sorts);
			}
			page = memberVipService.list(vip, si);
			pl = new MyPageLink(page.getPaging());
		} catch (Exception e) {
			error(log, e, "会员查询异常");
			return FORWARD_TIP;
		}
		
		model.addAttribute("list", page.getList());
		model.addAttribute("vip", vip);
		model.addAttribute("pl", pl);
		model.addAttribute("searchWord", si.getSearchWord());
		return "firm/memberVip_list";
	}
	
}
